/**
 * 支付跳转
 * @constructor
 */
function PayOrder(){
    this.orderNo=orderNo;
    this.pid=pid;

    this.variable= {
        $payBtn: $("#pay-btn")
    }
    this.ajaxUrl = {
        productDetail: "/product/{0}.do",//detail
        orderDetail:"/order/orderNo/{0}.do?userId={1}",
        alipayApi:"/shop/app/ecshop/alipay-api.jsp"
    }
    this.parmas= {
        WIDout_trade_no: this.orderNo,
        WIDsubject: "",
        WIDtotal_fee: "",
        WIDshow_url: "",
        WIDbody: ""
    }
    this.common = new common()   //通用
}
PayOrder.prototype.init=function(){
    var self=this;
    var user = JSON.parse(localStorage.getItem("user"));
    if (!user) {
        alert("登录超时,请重新登录!");
        location.href="/shop/app/login/login.jsp";
    } else {
        if (!!self.orderNo && !!self.pid) {
            self.getProduct();
            self.getOrder(user.id);
        }
    }
}
PayOrder.prototype.getProduct=function(){
    var self=this;
    $.ajax({
        type: "GET",
        url: self.ajaxUrl.productDetail.format(self.pid),
        dataType: "json",
        success: function (data) {
            var $bannerObj = self.common.evalJson(data);
            if (!!$bannerObj) {
                self.parmas.WIDsubject = $bannerObj.e.name;
                self.parmas.WIDshow_url = "http://"+window.location.host +"/shop/app/ecshop/ecshop-detail.jsp?pid=" + $bannerObj.e.id;
                self.parmas.WIDbody = $bannerObj.e.introduce;
            }
        }
    });
}
PayOrder.prototype.getOrder=function(uid){
    var self=this;
    $.ajax({
        type: "GET",
        url: self.ajaxUrl.orderDetail.format(self.orderNo,uid),
        dataType: "json",
        success: function (data) {
            var $bannerObj = self.common.evalJson(data);
            if (!!$bannerObj) {
                self.parmas.WIDtotal_fee = $bannerObj.orderInfo[0].amount;
                self.payBtn();
            }
        }
    });


}
PayOrder.prototype.payBtn=function() {
    var self = this;
    self.variable.$payBtn.click(function () {
        var payType=parseInt($('input:radio[name=payType]:checked').val());
        if(payType===2) {
            location.href = "/shop/app/ecshop/alipay-api.jsp?WIDout_trade_no=" + self.parmas.WIDout_trade_no + "&WIDsubject=" + self.parmas.WIDsubject + "&WIDtotal_fee=" + self.parmas.WIDtotal_fee + "&WIDshow_url=" + self.parmas.WIDshow_url + "&WIDbody=" + self.parmas.WIDbody;
        }
    });
}


$(function(){

    new PayOrder().init();
});